package com.itheima.demo5tcp2;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class TcpDemo1
{
    //客户端
    public static void main(String[] args) throws Exception {
        //创建Socket管道对象 请求和服务器连接
        Socket socket = new Socket("127.0.0.1", 10086);
        //从Socket管道中获取字节输入流
        //DataInputStream dis = new DataInputStream(socket.getInputStream());
        //创建一个扫描器
        Scanner sc = new Scanner(System.in);
        //从Socket管道中获取字节输出流
        while (true) {
            //从Socket管道中获取字节输出流
            DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
            System.out.println("请输入数据:");
            String data = sc.nextLine();
            if ("exit".equals(data)) {
                System.out.println("退出发送端...");
                //关闭
                socket.close();
                break;
            }
            //写入数据
            dos.writeUTF(data);
        }
    }
}
